Diagnose bad config files.
authorEwan Mellor <ewan@xensource.com>
Thu, 7 Dec 2006 17:47:43 +0000 (17:47 +0000)
committerEwan Mellor <ewan@xensource.com>
Thu, 7 Dec 2006 17:47:43 +0000 (17:47 +0000)
Signed-off-by: Ewan Mellor <ewan@xensource.com>
tools/python/xen/xm/main.py

index 9151848d30412816e3199781b8d981f32b39f87f..6850061908d1e2e5a4948f08130f864aa0dbc898 100644 (file)
@@ -335,17 +335,22 @@ all_commands = (domain_commands + host_commands + scheduler_commands +
 # Configuration File Parsing
 ##
 
+config = None
 if os.path.isfile(XM_CONFIG_FILE):
-    config = xml.dom.minidom.parse(XM_CONFIG_FILE)
-else:
-    config = None
+    try:
+        config = xml.dom.minidom.parse(XM_CONFIG_FILE)
+    except:
+        print >>sys.stderr, ('Ignoring invalid configuration file %s.' %
+                             XM_CONFIG_FILE)
 
 def parseServer():
     if config:
         server = config.getElementsByTagName('server')
         if server:
             st = server[0].getAttribute('type')
-            if st != SERVER_XEN_API:
+            if st != SERVER_XEN_API and st != SERVER_LEGACY_XMLRPC:
+                print >>sys.stderr, ('Invalid server type %s; using %s.' %
+                                     (st, SERVER_LEGACY_XMLRPC))
                 st = SERVER_LEGACY_XMLRPC
             return (st, server[0].getAttribute('uri'))